﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourImage
    {
        #region Common
        public eTourImage Data;
        public TourImage()
        {
            Data = new eTourImage();
        }

        ~TourImage()
        {
        }

        public virtual void Dispose()
        {
        }

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourImage objDAL = new cTourImage();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cTourImage objDAL = new cTourImage();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cTourImage objInfor = new cTourImage();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourImageID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        //Update nhung cai ma eTourImage Data dang nam giu thong qua cTourImage objInfor
        public int Update(int ID)
        {
            int nResult = 0;
            cTourImage objInfor = new cTourImage();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        private void MappingData(cTourImage objInfor)
        {
            objInfor.Filename = Data.Filename;
            objInfor.TourID = Data.TourID;
        }
        private void ConvertData(cTourImage objInfor)
        {
            Data.Filename = objInfor.Filename;
            Data.TourID = objInfor.TourID;
        }
        public DataTable Search(int TourID, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cTourImage objDAL = new cTourImage();
            tbResult = objDAL.Search(TourID, PageIndex, PageSize, ref  PageCount);
            return tbResult;
        }
        #endregion
    }
}
